package com.cj.http;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cj.Mapper.ReviewMapper;
import com.cj.models.BookReviews;
import com.cj.models.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/review")
public class ReviewForGet {
    @Autowired
    ReviewMapper reviewMapper;
    @GetMapping(path = "{bookid:\\d+}")
    public ResultModel loadReview(@PathVariable("bookid") int bookid){
        QueryWrapper<BookReviews> bookReviewsQueryWrapper = new QueryWrapper<BookReviews>();
        bookReviewsQueryWrapper.eq("book_id",bookid)
                .orderByDesc("r_id")
                .last("limit 5");
        return new ResultModel("success",reviewMapper.selectList(bookReviewsQueryWrapper));

    }


}
